<template>
	<view class="card bg-white u-m-t-20">
		<view @click="goDetail" class="u-p-t-28 u-p-r-28 u-p-l-28">
			<view class="border-b u-flex u-p-b-28">
				<view>
					<u-image border-radius="14px" width="115px" height="115px" :src="item.cover">
					</u-image>
				</view>
				<view class="right u-m-l-28">
					<view class="u-font-32 u-flex u-row-between">
						<view class="title u-line-1">{{item.title}}</view>
						<u-tag shape="circle" border-color="#FEF2BF" color="#333" :text="status_text" size="mini"
							mode="plain" />

					</view>
					<view class="info">
						<u-tag class="u-m-r-8" color="#333" :text="item.sex" size="mini" bg-color="#FEF2BF"
							mode="dark" />
						<u-tag class="u-m-r-8" color="#333" :text="item.category" size="mini" bg-color="#FEF2BF"
							mode="dark" />
					</view>


					<view class="u-line-1 u-font-12 color-80">{{item.district}}</view>

					<view v-if="type==='adopt'" class="u-line-2 u-font-12 color-80 u-m-t-8">{{item.story}}</view>

					<view v-if="type==='find_pet'" class="money">
						<view v-if="item.is_personally === 1">
							<text class="u-font-18">面议</text>
						</view>
						<view v-else>
							<text class="u-font-12">悬赏￥</text>
							<text class="u-font-18">{{item.reward}}</text>
						</view>
					</view>
					<view v-if="type==='find_master'" class="u-line-2 u-font-12 color-80 u-m-t-8">{{item.detail}}</view>

				</view>
			</view>


		</view>
		<view class="u-font-12 color-80 u-p-28 u-flex u-row-between">
			<text>{{item.create_time}}</text>
			<view class="u-flex">
				<!-- 送养 -->
				<view v-if="type==='adopt'">
					<!-- 1未审核 或者 2已通过 且 1未领养 才能编辑-->
					<u-tag @click="goPublishGetInfo"
						v-if="item.audit_status === 1 || (item.audit_status === 2 && item.status === 1)"
						class="u-m-l-28" shape="circle" color="#808080" text="编辑" size="mini" mode="plain" />

					<u-tag @click="setStatus" v-if="item.audit_status === 2 && item.status === 1" class="u-m-l-28"
						shape="circle" color="#FF3A3A" text="设为已领养" size="mini" mode="plain" />

					<u-tag @click="setStatus" v-if="item.status === 2" class="u-m-l-28" shape="circle" color="#FF3A3A"
						text="设为待领养" size="mini" mode="plain" />

					<!-- <u-tag @click="remove"
						v-if="item.audit_status === 1 || item.audit_status === 3 || (item.audit_status === 2 && item.status === 2)"
						class="u-m-l-28" shape="circle" color="#FF3C26" text="删除" size="mini" mode="plain" /> -->
				</view>

				<!-- 寻宠或寻主 -->
				<view v-else>
					<u-tag @click="goPublishFindPetOrMaster" v-if="item.status === 1" class="u-m-l-28" shape="circle"
						color="#808080" text="编辑" size="mini" mode="plain" />
					<u-tag @click="setStatus" v-if="item.status === 1" class="u-m-l-28" shape="circle" color="#FF3A3A"
						text="设为已完成" size="mini" mode="plain" />
					<!-- <u-tag @click="remove" class="u-m-l-28" shape="circle" color="#FF3A3A" text="删除" size="mini"
						mode="plain" /> -->
				</view>

			</view>
		</view>


	</view>
</template>

<script>
	import {
		myPublishDel,
		myPublishSetStatus
	} from '@/api/user';
	export default {
		name: "publishCard",
		props: ['item', 'type'],
		computed: {
			status_text() {
				if (this.type === 'adopt') { // 送养
					if (this.item.audit_status === 1) {
						return '未审核';
					} else if (this.item.audit_status === 2) {
						return this.item.status === 1 ? '未领养' : '已领养'
					} else {
						return '已拒绝';
					}
				} else {
					if (this.item.status === 1) {
						return '未完成'
					} else if (this.item.status === 2) {
						return '已完成'
					}

				}

			}
		},
		data() {
			return {};
		},
		methods: {
			goDetail() {

				console.log(this.type);
				let url = '';
				switch (this.type) {
					case 'adopt':
						url = '/pagesIndex/indexInfo/indexInfo?id=' + this.item.id
						break;
					case 'find_pet':
						url = `/pagesIndex/findInfo/findInfo?type=pet&id=${this.item.id}`
						break;
					case 'find_master':
						url = `/pagesIndex/findInfo/findInfo?type=master&id=${this.item.id}`
						break;
				}
				// 未审核的不能去详情页面
				if (this.type === 'adopt' && this.item.audit_status === 1) {
					uni.showModal({
						showCancel: false,
						content: '请等待后台审核',
						confirmColor: '#333',
					});
					return;
				}
				uni.navigateTo({
					url,
				})
			},
			async setStatus() {
				const res = await myPublishSetStatus({
					type: this.type,
					id: this.item.id,
					status: this.item.status === 1 ? 2 : 1
				})
				uni.showToast({
					title: res.msg,
					icon: "none",
					mask: true,
				});
				this.$emit('refresh');
			},
			remove() {
				uni.showModal({
					title: '提示',
					content: '确定删除该信息吗？',
					success: async (sub) => {
						if (sub.confirm) {
							const res = await myPublishDel({
								type: this.type,
								id: this.item.id,
							});
							uni.showToast({
								title: res.msg,
								icon: "none",
								mask: true,
							});
							this.$emit('refresh');
						}
					}
				});
			},
			goPublishGetInfo() {
				uni.navigateTo({
					url: '/pagesPublish/getInfo/getInfo?id=' + this.item.id
				})
			},
			goPublishFindPetOrMaster() {
				let url = '/pagesPublish/findPet/findPet?id=' + this.item.id;

				if (this.type === 'find_master') {
					url = '/pagesPublish/findSomeone/findSomeone?id=' + this.item.id
				}
				uni.navigateTo({
					url
				})
			}
		},
	}
</script>

<style lang="scss">
	.right {
		width: 61%;
		height: 115px;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
	}

	.card {
		border-radius: 6px;

		.money {
			color: #F34184;
		}

		.title {
			width: 280rpx;
		}
	}
</style>
